const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    port: 5555, // 您的端口号
    headers: {
      'Access-Control-Allow-Origin': '*'
    },
    open: true,
    proxy: {
      '/api': {
        target: 'https://server.dayi.org.cn/api',
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      },
      '/admin': {
        target: 'http://cn-zj-hz-1.govfrp.com:62092/api',
        changeOrigin: true,
        pathRewrite: {
          '^/admin': ''
        }
      }
    }
  }
})
// 获取主机id和IP地址
const os = require('os')

function getNetworkIp () {
  let needHost = '' // 打开的host
  try {
    // 获得网络接口列表
    const network = os.networkInterfaces()
    for (const dev in network) {
      const iface = network[dev]
      for (let i = 0; i < iface.length; i++) {
        const alias = iface[i]
        if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
          needHost = alias.address
        }
      }
    }
  } catch (e) {
    needHost = 'localhost'
  }
  return needHost
}

const myHost = getNetworkIp()
const myName = os.hostname()
process.env.VUE_APP_HOST = myHost// IP地址
process.env.VUE_APP_NAME = myName// 主机名
// 生成设备id
const idObj = require('node-machine-id')
const id = idObj.machineIdSync({ original: true })

process.env.VUE_APP_MACHINEID = id// 设备id
